package com.product.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.product.common.annotation.Log;
import com.product.common.core.controller.BaseController;
import com.product.common.core.domain.AjaxResult;
import com.product.common.enums.BusinessType;
import com.product.business.domain.PurchaseInfo;
import com.product.business.service.IPurchaseInfoService;
import com.product.common.utils.poi.ExcelUtil;
import com.product.common.core.page.TableDataInfo;

/**
 * 采购企业信息Controller
 *
 * @author wanghui
 * @date 2022-08-20
 */
@RestController
@RequestMapping("/business/purchase")
public class PurchaseInfoController extends BaseController {
    @Autowired
    private IPurchaseInfoService purchaseInfoService;

    /**
     * 查询采购企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchaseInfo purchaseInfo) {
        startPage();
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * @param purchaseInfo 购买信息
     * @return {@link TableDataInfo }
     * @Description 查询已审核采购企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:list')")
    @GetMapping("/listpass")
    public TableDataInfo listCheckPass(PurchaseInfo purchaseInfo) {
        startPage();
        purchaseInfo.setCompanyStatus("0");
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * @param purchaseInfo 购买信息
     * @return {@link TableDataInfo }
     * @Description 查询待审核采购企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:list')")
    @GetMapping("/listwait")
    public TableDataInfo listCheckWait(PurchaseInfo purchaseInfo) {
        startPage();
        purchaseInfo.setCompanyStatus("1");
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * @param purchaseInfo 购买信息
     * @return {@link TableDataInfo }
     * @Description 查询待整改采购企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:list')")
    @GetMapping("/listrectify")
    public TableDataInfo listCheckRectify(PurchaseInfo purchaseInfo) {
        startPage();
        purchaseInfo.setCompanyStatus("2");
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * @param purchaseInfo 购买信息
     * @return {@link TableDataInfo }
     * @Description 查询待取消采购企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:list')")
    @GetMapping("/listcancel")
    public TableDataInfo listCheckCancel(PurchaseInfo purchaseInfo) {
        startPage();
        purchaseInfo.setCompanyStatus("3");
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出采购企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:export')")
    @Log(title = "采购企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseInfo purchaseInfo) {
        List<PurchaseInfo> list = purchaseInfoService.selectPurchaseInfoList(purchaseInfo);
        ExcelUtil<PurchaseInfo> util = new ExcelUtil<PurchaseInfo>(PurchaseInfo.class);
        util.exportExcel(response, list, "采购企业信息数据");
    }

    /**
     * 获取采购企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId) {
        return AjaxResult.success(purchaseInfoService.selectPurchaseInfoByCompanyId(companyId));
    }

    /**
     * 新增采购企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:add')")
    @Log(title = "采购企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseInfo purchaseInfo) {
        return toAjax(purchaseInfoService.insertPurchaseInfo(purchaseInfo));
    }

    /**
     * 修改采购企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:edit')")
    @Log(title = "采购企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseInfo purchaseInfo) {

        return toAjax(purchaseInfoService.updatePurchaseInfo(purchaseInfo));
    }

    /**
     * 删除采购企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:purchase:remove')")
    @Log(title = "采购企业信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds) {
        return toAjax(purchaseInfoService.deletePurchaseInfoByCompanyIds(companyIds));
    }
}
